const data = [1,2,3,4,5,6,7,8,9,10];
// step = 2
// [1,5, 3,5, 5,5 ,7,5, 9,5]; // 方案
// const downSameple = (data, step) => {
//   const result = [];
//   for (let i = 0; i < data.length; i += step) {
//     const chunk = data.slice(i, i + step);
//     const avg = chunk.reduce((pre, cur) => pre + cur) / chunk.length;
//     result.push(avg);
//   }
//   return result;
// }
const downSameple = (data, step) => {
  const result = [];
  for (let i = 0; i < data.length; i += step) {
    const chunk = data.slice(i, i + step); // 拆分数据块
    let sum = 0;
    for (let j = 0; j < chunk.length; j++) {
      sum += chunk[j]; // 逐个累加数据块的元素
    }
    const avg = sum / chunk.length; // 计算平均值
    result.push(avg); // 将平均值存入结果
  }
  return result;
}
console.log('====================================');
console.log(downSameple(data, 2));
console.log('====================================');

